﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Windows.Forms;

namespace web.beispiele
{
    public partial class login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Int32 sessionId = bll.clsUser.Session;
            sessionId = 0;
        }

        /// <summary>
        /// wird bei Klick des Login-button aufgerufen
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void btnCompare_Click(object sender, System.EventArgs e)
        {
            bll.clsUser _newLogin = new bll.clsUser();
            bll.clsUserCollection _myLoginCol = new bll.clsUserCollection();
            String _name = LoginNameDropDown.Text;
            String _pw = LoginPW.Text;
            _newLogin =_myLoginCol.compareLogins(_name, _pw);
                if (_newLogin.Name.Equals(_name) && _newLogin.LoginPw.Equals(_pw))
                {
                    bll.clsUser.Session = _newLogin.ID;

                    switch (_newLogin.Position)
                    {
                        case "Projectleader": Response.Redirect("./projectLeader.aspx"); break;
                        case "Customer": Response.Redirect("./customer.aspx"); break;
                        case "Manager": Response.Redirect("./management.aspx"); break;
                        case "Controller": Response.Redirect("./controlling.aspx"); break;
                        case "Employee": Response.Redirect("./employee.aspx"); break;
                        default: ClientScript.RegisterStartupScript(typeof(Page), "test", "<script>alert('Hello');return false;</script>"); break;
                    }
                }
                else
                {
                    LoginFailedMsg.Text = "Login failed! Please try an other password or contact the system administrator";
                }
            
        }

        /// <summary>
        /// DropDownList für den Login
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        /// 
        protected void LoginNameDropDown_SelectedIndexChanged(object sender, EventArgs e)
        {
            bll.clsUser _myUser = new bll.clsUser();
            bll.clsUserCollection _myUserCol = new bll.clsUserCollection();
        }
    }
}